﻿/*
 * Erstellt mit SharpDevelop.
 * Benutzer: broox
 * Datum: 01.04.2009
 * Zeit: 12:34
 * 
 */
using System;
using System.Text.RegularExpressions;

namespace sEmit
{
	/// <summary>
	/// Description of AsciiEditing.
	/// </summary>
	public static class AsciiEditing
	{	
		public static string CharsToAscii(string value)
		{
			foreach(Match m in Regex.Matches(value, ("[aéàèëöüïäêûîôâ]"), RegexOptions.IgnoreCase))
			{
				string index = Convert.ToInt32(m.Value[0]).ToString();
				while(index.Length < 3)
				{
					index = ("0" + index);
				}
				value = value.Replace(m.Value, "&#" + index + ";");
			}
			
			return value;
		}
		
		public static string AsciitoChars(string value)
		{
			foreach(Match m in Regex.Matches(value, ("&amp;#\\d\\d\\d;"), RegexOptions.IgnoreCase))
			{
				value = value.Replace(m.Value, Char.ConvertFromUtf32(Convert.ToInt32(m.Value.Remove(0, 6).Remove(3, 1))).ToString());
			}
			
			return value;
		}
	}
}
